﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;


namespace Besture.UI.Admin.LabelManage
{
    public partial class GetTableColumn : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string tableName = StringHelper.Query("table");

            DataTable table =
                QueryDac.GetTable(
                    string.Format(
                        @"SELECT name, user_type_id, is_identity, '-' type
                FROM sys.all_columns 
                WHERE object_id in(
                    SELECT object_id 
                    FROM sys.all_objects 
                    WHERE name = '{0}')",
                        tableName));

            for (int i = 0; i < table.Rows.Count; i++)
            {
                int typeId = Convert.ToInt32(table.Rows[i]["user_type_id"].ToString());
                switch (typeId)
                {
                    case 56:
                        table.Rows[i]["type"] = "int";
                        break;
                    case 231:
                        table.Rows[i]["type"] = "nvarchar";
                        break;
                    case 35:
                        table.Rows[i]["type"] = "text";
                        break;
                    case 40:
                        table.Rows[i]["type"] = "date";
                        break;
                    case 61:
                        table.Rows[i]["type"] = "datetime";
                        break;
                    case 175:
                        table.Rows[i]["type"] = "char";
                        break;
                }
            }


            Response.Write(JsonHelper.ToJson(table));
            Response.End();
        }
    }
}